<template>
	<view class="tbody">
		<view v-for="item in rows" :key="item.id" @click="pageSkip(item.id)">
			<view class="articleBox">
				<image :src='URL + item.coverImage' mode="" class="articleBox-image" />
				<view class="articleBox-box">
					<!-- 标题 -->
					<view class="headline">
						<text v-if="kid === '4' || kid === '7' || kid === '0' || kid === '3'">{{item.title}}</text>
						<text v-if="kid === '6' || kid === '5' ||kid === '1' || kid === '2'">{{item.content}}</text>
						
					</view>
					<!-- 文章内容 -->
					<text class="text">
						<text v-if="kid === '4' || kid === '0'">{{item.introduce}}</text>
						<text v-if="kid === '5' || kid === '6' ||kid === '7' || kid === '1' || kid === '2' ||kid === '3'">{{item.content}}</text>
					</text>
					<!-- 学习人数 时间 -->
					<view class="state">
						<!-- 学习人数 -->
						<view class="state-left">

						</view>
						<view class="state-right">
							<!-- 发布人 -->
							<view class="state-right-one">
								<image src="/static/images/我的@2x.png" mode="" />
								<text class="state-right-one-name"
									style="margin-right: 20rpx;">{{item.createName}}</text>
							</view>
							<!-- 时间 -->
							<view class="state-right-one">
								<image src="../../static/images/时间@2x.png" mode="" style="margin-right: 6rpx;"></image>
								<text class="state-right-one-name">{{item.createTime}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				URL: this.$store.state.user.URL,
				kid: '', //页面跳转带来的id，判断需要渲染什么类型数据
				total: 10,
				rows: [],
				page_data: {
					pageNum: 1,
					pageSize: 10
				}
			};
		},

		onLoad(options) {
			this.kid = options.id
			// 判断要请求什么数据
			// -------- 普通用户 ---------
			// 0是参与过得活动（已经删除，关于0的可以删掉）
			// 1是做出的贡献
			// 2是提出的诉求
			// 3是参与过的学习
			// -------- 管理员 ---------
			// 4是发布过的活动
			// 5是打过分的贡献
			// 6是解答的诉求
			// 7是发布的学习
			if (options.id === '0') {
				this.getList('/business/content/participant')
			} else if (options.id === '1') {
				this.getList('business/contribution/personalList')
			} else if (options.id === '2') {
				this.getList('/business/appeal/personalList')
			} else if (options.id === '3') {
				this.getList('/business/learningcontent/learnedList')
			} else if (options.id === '4') {
				this.getList('/business/content/publishList')
			} else if (options.id === '5') {
				this.getList('/business/contribution/responseList')
			} else if (options.id === '6') {
				this.getList('/business/appeal/responseList')
			} else if (options.id === '7') {
				this.getList('/business/learningcontent/publishList')
			}
		},
		methods: {
			// 页面跳转
			pageSkip(id) {
				if (this.kid === '0' || this.kid === '4') {
					uni.navigateTo({
						url: `/pages/joinactivityDetails/joinactivityDetails?id=${id}`,
					})
				} else if (this.kid === '1' || this.kid === '5') {
					uni.navigateTo({
						url: `/pages/bossContribution/bossContribution?id=${id}`,
					})
				} else if (this.kid === '2') {
					uni.navigateTo({
						url: `/pages/appealDetails/appealDetails?id=${id}`,
					})
				} else if (this.kid === '6') {
					uni.navigateTo({
						url: `/pages/appealHelp/appealHelp?id=${id}`,
					})
				} else if (this.kid === '3' || this.kid === '7') {
					uni.navigateTo({
						url: `/pages/studyDetails/studyDetails?id=${id}`,
					})
				}
			},
			// 上拉加载
			onReachBottom() {
				//触发了上拉加载，请求下一页（10）条数据
				let allTotal = this.page_data.pageNum * this.page_data.pageSize

				if (allTotal < this.total) {
					this.page_data.pageNum++
					// 判断当前条数小于总条数
					if (this.kid === '0') {
						this.getbusinesscontent('/business/content/list')
					} else if (this.kid === '1') {
						this.getList('business/contribution/personalList')
					} else if (this.kid === '2') {
						this.getList('/business/appeal/personalList')
					} else if (this.kid === '3') {
						this.getList('/business/learningcontent/learnedList')
					} else if (this.kid === '4') {
						this.getList('/business/content/publishList')
					} else if (this.kid === '5') {
						this.getList('/business/contribution/responseList')
					} else if (this.kid === '6') {
						this.getList('/business/appeal/responseList')
					} else if (this.kid === '7') {
						this.getList('/business/learningcontent/publishList')
					}
				} else {
					uni.showToast({
						title: '已加载全部数据',
						icon: 'none'
					})
				}

			},
			async getList(urls) {
				const res = await uni.$http.get(urls, {
					params: this.page_data
				})
				res.data.rows.forEach((item, index) => {
					this.rows.push(item)
				})

				this.total = res.data.total
				// 正则移除内容的html标签  纯文字
				// 正则移除内容的html标签  纯文字
				for (let i = 0; i < this.rows.length; i++) {
				 if(this.rows[i].introduce){
						this.rows[i].introduce = this.rows[i].introduce.replace(/<[^>]*>/g, "");
					}else{
						this.rows[i].content = this.rows[i].content.replace(/<[^>]*>/g, "");
					}
				}
			}
		}
	}
</script>

<style lang="scss">
</style>